package com.zhhs.common.utils;

import com.zhhs.common.utils.uuid.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @description: 生成唯一识别码的工具类
 * @author: JiaLe
 * @date: 2022-11-22 16:06
 **/
public class CreateIdUtils {

    @Autowired
    private RedisTemplate redisTemplate;

    public static String[] chars =  new String[] {
            "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I",
            "J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

    /**
     * 生成唯一的UUid
     * @return
     */
    public static String createUUID(){
        StringBuffer shortBuffer = new StringBuffer();
        String uuid = UUID.randomUUID().toString();
        uuid = uuid.replace("-", "");
        for (int i =0 ;i < 8;i++){
            String str = uuid.substring(i * 4, i * 4 + 4);
            int X = Integer.parseInt(str, 16);
            shortBuffer.append(chars[X % 36]);
        }
        return shortBuffer.toString();
    }
}
